package com.school.chapter02.stack_;

public class Stack<T> implements IStack {
    final int maxsize = 100;
    Object elem[] = new Object[maxsize];
    int top;

    public Stack() {
        top = 0;
    }

    public void clear() {
        top = 0;
    }

    public int size() {
        return top;
    }

    public boolean isEmpty() {
        if (top > 0)
            return false;
        else
            return true;
    }

    public void push(Object data) {
        if (top == maxsize)
            System.out.print("stack overflow");
        else
            elem[top++] = data;//
    }

    public Object pop() {
        if (top == 0) {
            return 0;
        } else
            top--;
        return elem[top];

    }

    public Object peek() {
        if (top == 0)
            return 0;
        else
            return elem[top - 1];
    }
}
